import axios from "axios";
import wxAuthClient from "../utils/wxAuthClient";

class IdeaCanvasService {
  async getIdeaCanvas(idea) {
    const response = await axios.get(
      `https://jishuba.cn/wp-json/ic/v1/get-idea?idea=${idea}`,
      {
        headers: {
        //   Authorization: wxAuthClient.getUserLocal().id,
        },
      }
    );
    return response.data;
  }

  async createIdeaCanvas(title, idea) {
    try {
      console.log("createIdeaCanvas", title, idea);
      const response = await axios.post(
        "https://jishuba.cn/wp-json/ic/idea/create",
        {
          title: title,
          idea: idea,
        },
        {
          headers: {
            "Content-Type": "application/json",
          },
        }
      );
      return response.data;
    } catch (error) {
      console.error("Error creating idea canvas", error);
    }
  }

  async getIdeas() {
    const response = await axios.get(
      "https://jishuba.cn/wp-json/ic/idea/list",
      {
        headers: {
        //   Authorization: wxAuthClient.getUserLocal()?.id,
        },
      }
    );
    return response.data;
  }

  async deleteIdea(id) {
    const response = await axios.delete(
      `https://jishuba.cn/wp-json/ic/idea/${id}`,
      {
        headers: {
        //   Authorization: wxAuthClient.getUserLocal().id,
        },
      }
    );
    return response.data;
  }
}

const ideaCanvasService = new IdeaCanvasService();
export default ideaCanvasService;
